package com.ylq.todolsitserver.mapper;

import com.ylq.todolsitserver.entity.Task;
import com.ylq.todolsitserver.vo.TaskVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface TaskMapper {

    @Insert("INSERT INTO tasks(title, description, status, priority, " +
            "category_id,due_date, created_time, updated_time) " +
            "VALUES(#{title}, #{description}, #{status}, #{priority}, " +
            "#{categoryId},#{dueDate}, NOW(), NOW())")
    void insert(TaskVO taskVO);

    @Select("SELECT * FROM tasks")
    List<Task> findAll(String status, String priority, Integer categoryId, Boolean upcoming);

    @Select("SELECT * FROM tasks WHERE id = #{id}")
    Task findById(Integer id);

    @Update("UPDATE tasks SET title = #{title}, description = #{description}, " +
            "status = #{status}, priority = #{priority}, category_id = #{categoryId}, " +
            "updated_time = NOW(),due_date = #{dueDate} WHERE id = #{id}")
    void update(TaskVO taskVO);

    @Delete("DELETE FROM tasks WHERE id = #{id}")
    void delete(Integer id);

    @Update("UPDATE tasks SET status = #{status} WHERE id = #{id}")
    void updateStatus(Integer id, String status);
}